package com.ruoyi.system.controller;

import java.math.BigDecimal;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.OrderList;
import com.ruoyi.system.service.IOrderListService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单明细Controller
 * 
 * @author ruoyi
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/system/order-list")
public class OrderListController extends BaseController
{
    @Autowired
    private IOrderListService orderListService;

    @PreAuthorize("@ss.hasPermi('system:list:kucun')")
    @GetMapping("/kucun")
    public AjaxResult kucun(@RequestParam("userId")String userId)
    {
        BigDecimal count = orderListService.getKucunValue(userId);

        return AjaxResult.success(count);
    }

    /**
     * 查询订单明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:list:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderList orderList)
    {
        startPage();
        List<OrderList> list = orderListService.selectOrderListList(orderList);
        return getDataTable(list);
    }

    /**
     * 查询订单明细列表 new  路径名字要小写，，大小写无所谓 根路径一定要正确！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！
     */
//    @PreAuthorize("@ss.hasPermi('system:list:new-list')")
    @GetMapping("/newlist")
    public TableDataInfo newList(OrderList orderList)
    {

        startPage();
        List<OrderList> list = orderListService.selectOrderListNew(orderList);
        return getDataTable(list);
    }


    /**
     * 导出订单明细列表
     */
    @PreAuthorize("@ss.hasPermi('system:list:export')")
    @Log(title = "订单明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderList orderList)
    {
        List<OrderList> list = orderListService.selectOrderListList(orderList);
        ExcelUtil<OrderList> util = new ExcelUtil<OrderList>(OrderList.class);
        util.exportExcel(response, list, "订单明细数据");
    }

    /**
     * 获取订单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:list:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(orderListService.selectOrderListById(id));
    }

    /**
     * 新增订单明细
     */
    @PreAuthorize("@ss.hasPermi('system:list:add')")
    @Log(title = "订单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderList orderList)
    {
        return toAjax(orderListService.insertOrderList(orderList));
    }

    /**
     * 修改订单明细
     */
    @PreAuthorize("@ss.hasPermi('system:list:edit')")
    @Log(title = "订单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderList orderList)
    {
        return toAjax(orderListService.updateOrderList(orderList));
    }

    /**
     * 删除订单明细
     */
    @PreAuthorize("@ss.hasPermi('system:list:remove')")
    @Log(title = "订单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(orderListService.deleteOrderListByIds(ids));
    }
}
